<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
	<meta http-equiv="content-type" content="text/html;charset=utf-8" />
	<title>AXL Tutorial: TranzAm</title>
	<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<!-- menu -->
	<div id="navmain">
	<ul>
		<li><a href="index.html">Overview</a></li>
		<li><a href="install.html">Installation</a></li>
		<li><a href="config.html">Configurator</a></li>
		<li><a href="animation.html">Animation</a></li>
		<li><a href="framework.html">Framework</a></li>
		<li><a href="tranzam.html">Tutorial</a></li>
	</ul>
	</div>
	<div id="navsub">
	<ul>
		<li><a href="tranzam.html">Start</a></li>
		<li><a href="tranzam_a1.html">Article 1</a></li>
		<li><a href="tranzam_a2.html">Article 2</a></li>
		<li><a href="tranzam_a3.html">Article 3</a></li>
		<li><a href="tranzam_a4.html">Article 4</a></li>
		<li><a href="tranzam_a5.html">Article 5</a></li>
		<li><a href="tranzam_a6.html">Article 6</a></li>
		<li><a href="tranzam_a7.html">Article 7</a></li>
		<li><a href="tranzam_a8.html">Article 8</a></li>
		<li><a href="tranzam_a9.html">Article 9</a></li>
		<li><a href="tranzam_a10.html">Article 10</a></li>
	</ul><span class="smallprint">This menu will stay fixed with a proper browser.</span>
	<p>
	 <a href="http://jigsaw.w3.org/css-validator/">
	  <img style="border:0;width:88px;height:31px"
		   src="http://jigsaw.w3.org/css-validator/images/vcss" 
		   alt="Valid CSS!" />
	 </a>
	</p>
	<p>
      <a href="http://validator.w3.org/check?uri=referer"><img
          src="http://www.w3.org/Icons/valid-xhtml10"
          alt="Valid XHTML 1.0!" height="31" width="88" /></a>
    </p>
<p><a href="http://www.bloggerheads.com/bbc/"><img src="http://www.bloggerheads.com/bbc/bbc.gif" width="90" height="45"  
alt="Click here to find out why." /></a></p>
<p><a href="http://retrospec.sgn.net" ><img src="retrospec.gif" width="150" alt="Fine games" /></a></p>
	</div>
<!-- menu -->

	<div id="main">
	<a name="files"></a>
<h1>Introduction</h1>
In the previous lesson we created a basic car class and used it to move around the map. In this lesson we'll be making the car's 
movement a bit better and populating some of the display panel's sections (time played, distance travelled, fuel, temperature).
<br />The Car panel and the sections being populated in this lesson are shown in the image below:<br />
<img src="images/tranzam_panel.jpg" alt="panel" />
<h1>Structure</h1>
If you are manually creating the project 
    make file then use the one from lesson 3 as the same files are being used.
    <br />The following files will be changed in this lesson:
    <ul>
    <li>game_vars.cpp will be updated to include some new graphics/animations (the Speedometer, Temperature Gauge, Fuel, Lives)</li>
    <li>game_transam.cpp: this is where the animations are initialised and so will include those listed in the previous item</li>
    <li>game_game.cpp: It is here where the new time played statistic is updated. This is shown on the car's panel (the graphic to the left of the main map window)
    <li>game_game.cpp: It is here where the new animations for the car's panel are shown (temperature, etc)</li>
    <li>game_car.h : Most of the changes are within the Car class to include the statistics already mentioned, including temperature, fuel, distance travelled, etc.</li>
    <li>game_car.cpp : This includes the code to implement the new features and a few more updates to the car's handling: There will be a 'handbrake' key added to allow the car to be stopped more quickly, two modes of driving and minor tweaks to the way the car handles</li>
    </ul>
	<a name="source1"></a>
<h1>Animations</h1>
In the animations.xml file are references to the following graphics (indicated by the 'id' attribute): speedo, fuel, temperature<br />
<img style="float: right" src="images/tranzam_strips.jpg" alt="strips" />
These are located in the graphics file transam.bmp and are the horizontal coloured strips. 
They are used to represent the speed of the car, the amount of fuel and the car's temperature.
<h1>TranzAm</h1>
The car will be controlled by the cursor keys. Cursors control turning and acceleration/braking. The Left Shift key can now be used as a hand-brake. 
In this release, it will simply slow down the car quicker.
<br />
The instruments/values in the game (on car panel as shown above) will function as follows:
<ul>
<li>Time: Seconds played (hopefully will take approximately the same time to navigate the width/height of the map as it does in the original Tranz-Am game). About 30 and 50 seconds</li>
<li>Miles: Set to match (approximately) the same speed as the original Tranz-Am game, and to reflect the same distance (currently this is MPH/10) - about 800 miles in 15 seconds</li>
<li>Fuel: A full tank will last about one minute at full speed</li>
<li>Temperature: At full speed will hit danger (red) in 30 seconds and will only decrease when speed is decreased</li>
<li>Speed: Upto 500. 0-300 is green, 300-400 is yellow and 400-500 is red</li>
</ul>
There is a link between temperature and speed. When speed enters the red area the temperature will increase, when the speed is in the yellow area the temperature 
remains the same, when the speed is in the green temperature will decrease. Once temperature reaches the maximum the car will cut-out and cannot be accelerated until 
the temperature is out of the danger red area. When the car has 'cut-out' it will reduce to a slow speed, making it vulnerable to attack.
<br />
For future versions we will be implementing some more features such as, collision with objects will result in the temperature hitting red (i.e. the car will cut-out) and damage sustained, and 
enemies will follow the car based on set rules and will use an A* algorithm for determing the route to take.
<br/>
This version will see two control methods added (though in later lessons this is removed as I decided to stick to one!). Both methods alter the way 
acceleration works - the first mode will accelerate when up cursor is pressed and decelerate slowly when released, the second mode will not decelerate 
when released.

<h1>Code Walkthrough (game_vars.cpp/game_transam.h/game_transam.cpp)</h1>
The animations for the additional graphics are added. Additional animations are loaded very simply and are done so via the Animation class constructor in the SetupGame function in the game_transam.cpp file. 
For example, the temperature gauge is loaded as follows:
<div class="code">
DisplayTemperature	=new Animation(GameLibrary,"temperature");
</div>

Where 'temperature' is the animation referenced in the animations.xml file with the id attribute of 'temperature'.<br />
So far all of our animations have actually been static graphics. In the next lesson we will add the menu and a proper animation will be used and a more optimised 
method of referencing static graphics shown.

<h1>Code Walkthrough (game_game.cpp)</h1>
This file contains our two automated callback functions: TransAmGameLogic and TransAmGameDrawing. 
<br />
The changes to this file are minimal and are as follows:
<ol>
<li>The TransAmGameLogic is updated to increase the 'time' entry. Because this function is guaranteed to be called every frame, and we have set the FPS to be 60, we can simply update a variable once per call and every 60 times we have one second. The Configuration object can give us the fps - <span class="code">GameConfiguration->CapsSystem.fps</span>
. Remember, 'GameConfiguration' is our variable initialised in the SetupGame function from the AXL Framework</li>
<li>The TransAmGameDrawing is updated to draw the additional items. These are simply Allegro blit/draw_sprite functions using the Animations we have added. Remember the Animation public data member ReadOnly_CurrentItem returns the Animation's 
current graphic item. As a reminder, the destination bitmap, as always, is the AXL Framework's DrawingSurface. The DrawingSurface is determined by the config.xml file and will either be a memory or video bitmap and will be drawn to 
the screen using double buffering, triple buffering or page flipping.
</ol>

<h1>Code Walkthrough (game_car.cpp/game_car.h)</h1>
First up, for all the new features we are adding, we need some variables. In the game_car.h header file we create new member variables for 
temperature, handbrake, distance travelled and a few constants to help us out with calculating the speed, temperature and fuel values.<br />
The temperature and fuel values are calculated and increased/decreased according to the specification set out above in the 'TranzAm' section.
<br />
NextMove() is the car's main update method and is called once per frame from the TransAmGameLogic() function (as has always been the case). So it is clear 
(hopefully) that all updates to fuel, temperature, distance and speed will be done here too.<br />
The changes to this method (sometimes the code in the lessons are best viewed using a file diff program - e.g. WinMerge - this is how I'm writing this tutorial, btw) are as follows:
<ul>
<li>Fuel is decreased based on the car's speed</li>
<li>If handbrake key is pressed, then deceleration is increased</li>
<li>Miles driven is increased</li>
<li>Speed is calculated</li>
<li>Temperature is increased/decreased based on the car's speed</li>
</ul>
Note: all the code above was based on trial and error, there sometimes isn't a magic way of doing something!
<br />
The only odd thing about this function is the addition of the second driving mode 'simple acceleration' that was mentioned earlier. This simply adjusts the way 
the car is moved. To see it working in this version, alter the variable 'SimpleAcceleration' in the Car::SetupCar method at the top of the source file. In the previous 
lessons only one driving mode was available - this hasn't really changed, just moved around to accomodate this second mode.
<br />And as it happens, later on you will see this second driving mode removed as I found it a bit pants.

<h1>Allegro</h1>
Again, very little Allegro knowledge has been required, other than using the draw_sprite (masked blitting) and blit (non-masked blitting).
<br />So, all that's required is to compile, run and see the changes. Note, there are no fuel pick-ups in the current version so when you run out of fuel, 
you will have to quit by pressing the ESCape key. In a later lesson we will making all the foreground objects on the map active (such as fuel and the collision items like trees, etc)
and learning how to store custom values for tiles that can be used in code. I've also noticed this version sometimes 
crashes on exit, but rest assured it doesn't in later versions.
<h1>Next</h1>
In the next lesson, the game will not change as such as we will be making a menu system. The menu system will be created 
to show you how the AXL Configuration class loads and saves values, how to create custom file based configuration items, how to change your game to 
use double/triple/paging buffering techniques, how to switch between windowed and fullscreen, how to change the game's FPS, how to use and up date an animation, 
plus a few more things.
</div>
</body>
</html>
